﻿using Microsoft.AspNetCore.Authorization;

namespace S.Authorization.Read.API.Extensions.Custom
{
    public class PermissionRequirementHandler : AuthorizationHandler<PermissionRequirement>
    {
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, PermissionRequirement requirement)
        {
            // 在这里实现检查用户是否具有特定权限的逻辑
            if (context.User.HasClaim(c => c.Type == "Permission" && c.Value == requirement.PermissionName))
            {
                context.Succeed(requirement);
            }
            else
            {
                context.Fail();
            }
            return Task.CompletedTask;
        }
    }

}
 